/*
 * @Description:
 * @Author:
 * @Date: 2024-11-02 13:47:45
 * @LastEditTime: 2024-11-02 22:29:12
 * @LastEditors: XXX
 */
import type { ActionTree, ActionContext } from 'vuex'
import type { Mutations } from './mutations'
import type { SettingState } from './state'
import type { RootState } from '@/store'
import { SettingsActionTypes } from './action-types'
import { SettingsMutationTypes } from './mutation-types'

type PayloadType = {
  key: string
  value: any
}

type AugmentedActionContext = {
  commit<K extends keyof Mutations> (
    key: K,
    payload: Parameters<Mutations[K]>[1]
  ): ReturnType<Mutations[K]>
} & Omit<ActionContext<SettingState, RootState>, 'commit'>

export interface Actions {
  [SettingsActionTypes.ACTION_CHANGE_SETTING] (
    { commit }: AugmentedActionContext,
    payload: PayloadType
  ): void
}

export const actions: ActionTree<SettingState, RootState> & Actions = {
  [SettingsActionTypes.ACTION_CHANGE_SETTING] ({ commit }: AugmentedActionContext, payload: PayloadType) {
    commit(SettingsMutationTypes.CHANGE_SETTING, payload)
  }
}
